<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <h:head>

        <title>Orgãos</title>

    </h:head>

    <ui:composition template="/index.xhtml">  

        <ui:define name="conteudo">  

            <f:view>

                <h:body>

                    <h:form id="formOrgaos" >

                        <p:growl autoUpdate="true" showDetail="true"/>

                        <p:panel header="Orgãos">

                            <p:dataTable id="dtOrgaos"
                                         var="item" 
                                         value="#{orgaoBean.orgaos}" 
                                         selectionMode="single" 
                                         selection="#{orgaoBean.orgao}"
                                         rowKey="#{item.id}"
                                         emptyMessage="N&atilde;o h&aacute; dados">

                                <p:column headerText="C&oacute;digo" 
                                          style="width: 50px"> 
                                    <center>
                                        <h:outputText value="#{item.codigo}" />
                                    </center>
                                </p:column> 

                                <p:column headerText="Nome" > 
                                    <h:outputText value="#{item.nome}" />
                                </p:column>  

                            </p:dataTable>

                            <br/>

                            <!-- Botões para o CRUD -->

                            <p:commandButton value="Novo" 
                                             actionListener="#{orgaoBean.adicionarInicio}"
                                             oncomplete="dlgOrgao.show()" 
                                             update=":display"/>

                            <p:commandButton value="Editar" 
                                             actionListener="#{orgaoBean.editarInicio}"
                                             update=":display"/>

                            <p:commandButton value="Excluir"
                                             actionListener="#{orgaoBean.excluirInicio}"/>

                        </p:panel>
                        
                    </h:form>

                        <!-- confirmDialog para confirmação de exclusão -->

                        <p:confirmDialog  message="Deseja excluir esse registro?"
                                          severity="alert"
                                          header="Exclus&atilde;o" 
                                          widgetVar="dlgExcluirOrgao" 
                                          appendToBody="true">  

                            <h:form>

                                <p:commandButton id="confirm" 
                                                 value="Sim" 
                                                 actionListener="#{orgaoBean.excluirFim}" 
                                                 update=":formOrgaos:dtOrgaos"/>  

                                <p:commandButton id="decline"
                                                 value="N&atilde;o" 
                                                 onclick="dlgExcluirOrgao.hide();"
                                                 actionListener="#{orgaoBean.cancelar}" 
                                                 update=":formOrgaos:dtOrgaos" />   

                            </h:form>

                        </p:confirmDialog>

                        <p:dialog header="Órgão" 
                                  widgetVar="dlgOrgao" 
                                  appendToBody="true" 
                                  showEffect="clip"
                                  hideEffect="clip"
                                  dynamic="true"
                                  modal="true"
                                  resizable="false">

                            <h:panelGrid id="display">

                                <ui:include src="Orgao.xhtml" />

                            </h:panelGrid>

                        </p:dialog>

                </h:body>

            </f:view>

        </ui:define>

    </ui:composition>

</html>

